/*
 * Copyright 2025 arisgo@163.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.arisgo.cloud.attendance.clazz.service.impl;

import com.arisgo.cloud.common.Pagination;
import com.arisgo.cloud.web.mybatis.service.CloudServiceImpl;
import com.arisgo.cloud.attendance.clazz.mapper.GroupMapper;
import com.arisgo.cloud.attendance.clazz.service.GroupService;
import com.arisgo.cloud.attendance.clazz.entity.Group;
import com.arisgo.cloud.attendance.clazz.vo.GroupVo;
import com.arisgo.cloud.web.param.Paging;
import com.arisgo.cloud.web.utils.RequestUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 排班组
 *
 * @author Coulson
 * @since 2025-03-26
 */
@Service
public class GroupServiceImpl extends CloudServiceImpl<GroupMapper, Group, GroupVo> implements GroupService {

    @Override
    public Group getInstanceModel() {
        return new Group();
    }

    @Override
    public GroupVo getInstanceVo() {
        return new GroupVo();
    }

    @Override
    public Pagination<GroupVo> pageGroup(Paging page) {
        page.addTenantIdParam(RequestUtil.getTenantId());
        Map<String, Object> params = page.convertMap();

        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        PageInfo<GroupVo> pageInfo = new PageInfo<>(this.mapper.pageGroup(params));
        return Pagination.creator(page.getPageNo(), page.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
    }
}
